const App = getApp();
let touchDotX = 0; //X按下时坐标
let touchDotY = 0; //y按下时坐标
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLogin: false,
    userInfo: {}, // 用户信息
    orderCount: {}, // 订单数量
    toolList:[
      {
        img:'../../images/41.png',
        name:'就诊人管理',
        link:'/pages/patient/index',
        button:''
      },
      {
        img:'../../images/432.png',
        name:'陪诊师入驻',
        link:'/pages/physician/index',
        button:''
      },
      {
        img:'../../images/42.png',
        name:'地址管理',
        link:'/pages/address/index',
        button:''
      },
      {
        img:'../../images/431.png',
        name:'人工客服',
        link:'',
        button:'contact'
      },
      {
        img:'../../images/44.png',
        name:'分销中心',
        link:'/pages/dealer/index/index',
        button:''
      },
    ],
    isFront1: true,
    isFront2: true,
    isFront3: true,
    animationData1: {},
    animationData2: {},
    animationData3: {},
    ballTop1: 240,
    ballTop2: 230,
    ballTop3: 220,
    ballWidth1: 680,
    ballWidth2: 640,
    ballWidth3: 605,
    index1: 3,
    index2: 2,
    index3: 1,
    statusBarHeight: getApp().globalData.statusBarHeight,
    peopleList:[],
    examine_state:'',
    detail:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let _this = this;
    _this.setData({
      isLogin: App.checkIsLogin()
    });
    // 获取当前用户信息
    _this.getUserDetail();
    // 更新购物车角标
    App.setCartTabBadge();
    _this.getPeople();
    _this.getInfo();
  },
  getPeople(){
    let _this = this;
    App._get('patient/index', {
    }, result => {
      // 设置顶部导航栏栏
      _this.setData({
        peopleList:result.data.list
      });
    });
  },
  /**
   * 获取当前用户信息
   */
  getUserDetail() {
    let _this = this;
    App._get('user.index/detail', {}, function (result) {
      _this.setData(result.data);
    });
  },

  /**
   * 订单导航跳转
   */
  onTargetOrder(e) {
    let _this = this;
    if (!_this.onCheckLogin()) {
      return false;
    }
    let urls = {
      all: '/pages/order/index?type=all',
      payment: '/pages/order/index?type=payment',
      received: '/pages/order/index?type=received',
      refund: '/pages/order/refund/index',
    };
    // 转跳指定的页面
    wx.redirectTo({
      url: urls[e.currentTarget.dataset.type]
    })
  },

  /**
   * 菜单列表导航跳转
   */
  onTargetMenus(e) {
    let _this = this;
    if (!_this.onCheckLogin()) {
      return false;
    }
    wx.redirectTo({
      url: '/' + e.currentTarget.dataset.url
    })
  },

  /**
   * 跳转我的钱包页面
   */
  onTargetWallet(e) {
    let _this = this;
    if (!_this.onCheckLogin()) {
      return false;
    }
    wx.redirectTo({
      url: './wallet/index'
    })
  },

  /**
   * 跳转积分明细页
   */
  onTargetPoints(e) {
    let _this = this;
    if (!_this.onCheckLogin()) {
      return false;
    }
    wx.redirectTo({
      url: '../points/log/index'
    });
  },

  /**
   * 跳转到登录页
   */
  onLogin() {
    // wx.redirectTo({
    //   url: '../login/login',
    // });
    App.doLogin();
  },

  /**
   * 验证是否已登录
   */
  onCheckLogin() {
    let _this = this;
    if (!_this.data.isLogin) {
      App.showError('很抱歉，您还没有登录');
      return false;
    }
    return true;
  },
  onToPage(e){
    console.log(e)
    var url=e.currentTarget.dataset.link;
    console.log(this.data.detail,111)
    
    if(url=='/pages/physician/index'){
      if(this.data.detail==null){
        wx.reLaunch({
          url: '/pages/physician/index'
        })
      }else if(this.data.examine_state=='0'){
        wx.reLaunch({
          url: '/pages/physician/index?examine_state='+this.data.examine_state,
        })
      }else if(this.data.examine_state=='1'){
        wx.redirectTo({
          url: '/packageA/pages/end/index',
        })
      }else{
        wx.redirectTo({
          url: '/pages/physician/index?examine_state='+this.data.examine_state,
        })
      }
     
    }else {
      wx.navigateTo({
        url: url,
      })
    }
   
    var phone1='0351-2158173';
    var phone2='15235114280';
    if(url==''){
      wx.showActionSheet({
        itemList:[
         '0351-2158173','15235114280'
        ],
        success(res) {
          if (res.tapIndex === 0) {
              wx.makePhoneCall({
                  phoneNumber: phone1,
                  success: function () {
                      console.log('拨打电话成功' + phone1)
                  },
                  fail: function () {
                      console.log("拨打电话失败")
                  }
              })
          } else if (res.tapIndex === 1) {
              wx.makePhoneCall({ 
                  phoneNumber: phone2,
                  success: function () {
                      console.log('拨打电话成功' + phone2)
                  },
                  fail: function () {
                      console.log("拨打电话失败")
                  }
              })
          }
      },
      })
    }
    
  },
   getInfo(){
    let _this = this;
    App._get('accompany_info/detail', {
      user_id:wx.getStorageSync('user_id')
    }, result => {
      // 设置顶部导航栏栏
      _this.setData({
        detail:result.data.detail,
        examine_state:result.data.detail.examine_state
      });
    });
  },
})